#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
    string s;
    vector<string> vs;
    size_t pos = -1;
    int prev = 0;
    std::getline(cin, s);
    while ((pos = s.find(" ", pos + 1)) != std::string::npos)
    {
        auto str = s.substr(prev, pos - prev);
        cout << str << endl;
        vs.emplace_back(str);
        prev = pos + 1;
    }
    vs.emplace_back(s.substr(prev));
    std::reverse(vs.begin(), vs.end());
    for (auto &x : vs)
        cout << x << " ";
    return 0;
}